package com.woniuxy.lrz.carlproject.controller;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.lrz.carlproject.common.AppException;
import com.woniuxy.lrz.carlproject.common.Log;
import com.woniuxy.lrz.carlproject.common.Result;
import com.woniuxy.lrz.carlproject.model.OrderInfo;
import com.woniuxy.lrz.carlproject.service.OrderInfoService;
import com.woniuxy.lrz.carlproject.service.dto.orderDto.OrderInfoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单详情表 前端控制器
 * </p>
 *
 * @author lrz
 * @since 2022-09-28
 */
@RestController
@RequestMapping("/orderInfo")
@Slf4j
@Api("订单详情接口")
public class OrderInfoController {


    @Resource
    private OrderInfoService orderInfoService;

    @GetMapping("/getOrderInfoById")
    @Log("根据订单id查看订单详情")
    @ApiOperation("根据订单id查看订单详情")
    @ApiImplicitParam("订单id")
        public Result getOrderInfoById(int orderId) {
        log.info("订单id:{}",orderId);
        if (orderId<1){
            throw  new AppException("参数错误");
        }
        List<OrderInfo> orderInfoById =orderInfoService.getOrderInfoById(orderId);

        List<OrderInfoDto> orderInfoDtos = BeanUtil.copyToList(orderInfoById, OrderInfoDto.class);
        return Result.success(orderInfoDtos);
    }
}
